import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Put,
  UseGuards,
} from '@nestjs/common';
import { ModelService } from './model.service';
import { CreateModelDto } from './dto/create-model.dto';
import { UpdateModelDto } from './dto/update-model.dto';
import { QueryPageDto } from '../../common/dto/query.page.dto';
import { QueryModelDto } from './dto/query-model.dto';
import { Prisma } from '@prisma/client';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';

@Controller('model')
@ApiTags('型号管理')
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
export class ModelController {
  constructor(private readonly modelService: ModelService) {}

  @Post()
  create(@Body() createModelDto: CreateModelDto) {
    return this.modelService.createModel<CreateModelDto>(createModelDto);
  }

  @Post('page')
  findByPage(@Body() query: QueryPageDto<QueryModelDto>) {
    const where: Prisma.modelWhereInput = {
      isDelete: false,
      name: {
        contains: query.model.name || undefined,
      },
    };

    return this.modelService.queryPage(query, where);
  }
  @Get()
  findAll() {
    return this.modelService.findAll({
      isDelete: false,
    });
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.modelService.findOne(id);
  }

  @Put(':id')
  update(@Param('id') id: string, @Body() updateModelDto: UpdateModelDto) {
    return this.modelService.updateModel<UpdateModelDto>(id, updateModelDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.modelService.delete(id);
  }
}
